package co.qingke.resteasy.spring.rest;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import co.qingke.resteasy.spring.model.HelloMessage;
import co.qingke.resteasy.spring.model.HelloResponse;
import co.qingke.resteasy.spring.server.HelloSpringService;

@Component
@Path("/Hello")
public class HelloRestService {
    

    @Autowired
    private HelloSpringService halloService;

    // curl http://localhost:8080/resteasy_spring/rest/Hello/text?msg=Hi%20There
    @GET
    @Path("/text")
    @Produces(MediaType.APPLICATION_JSON)
    public Response sayTextHello(@QueryParam("msg") String msg) {
        String resp = halloService.sayTextHello(msg);
        return Response.ok(resp).build();
    }

    // curl -X POST -H "Content-Type: application/json" -d '{"msg":"Hi There","gender":"MALE"}'
    // http://localhost:8080/resteasy_spring/rest/Hello/javabean
    @POST
    @Path("javabean")
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    public Response sayJavaBeanHello(HelloMessage msg) {
        HelloResponse resp = halloService.sayJavaBeanHello(msg);
        return Response.ok(resp).build();
    }
}
